package me.hl.feign;

import feign.Feign;
import feign.gson.GsonDecoder;
import feign.okhttp.OkHttpClient;
import feign.slf4j.Slf4jLogger;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by haoliang on 2016/8/1.
 * example https://github.com/OpenFeign/feign/blob/master/example-wikipedia/src/main/java/feign/example/wikipedia/WikipediaExample.java
 */
public class FeignDemo {

    private static Logger logger = LoggerFactory.getLogger(FeignDemo.class);

    private static Feign.Builder feignDecoderBuilder = Feign.builder().decoder(new GsonDecoder()).client(new OkHttpClient())
            .logger(new Slf4jLogger(FeignDemo.class)).logLevel(feign.Logger.Level.FULL);

    private static Feign.Builder feignNoDecoderBuilder = Feign.builder().client(new OkHttpClient())
            .logger(new Slf4jLogger(FeignDemo.class)).logLevel(feign.Logger.Level.FULL);

    @Test
    public void feignTest() {
        try {
            CheckService checkService = feignNoDecoderBuilder.target(CheckService.class, "http://www.67960.com/");
            logger.info(checkService.check(URLEncoder.encode("测试", "UTF-8")));
        } catch (UnsupportedEncodingException e) {
            logger.error("", e);
        }
    }


}
